/*
 * @Author: Clark
 * @Email: haixuanwoTxh@gmail.com
 * @Date: 2022-10-13 16:13:04
 * @LastEditors: Clark
 * @LastEditTime: 2022-10-15 10:55:20
 * @Description: file content
 */

#include "protocol.h"

Protocol::Protocol()
{

}

bool Protocol::build_packet()
{
    return true;
}


bool Protocol::parse_packet()
{
    return true;
}

/**
 * @brief 获取parity校验码，数据的字节异或
 * @param data 		数据
 * @param dataLen	数据长度
 * @param checksum	校验码结果
 * @return true		成功
 * @return false	失败
 */
bool Protocol::get_xor_checksum(uint8_t *data, int dataLen, uint8_t *checksum)
{
    if (NULL == data || dataLen <= 0 || NULL == checksum)
    {
        log_debug("get checksum fail");
        return false;
    }

    unsigned char value = data[0];
    for (int i = 1; i < dataLen; i++)
    {
        value ^= data[i];
    }

    *checksum = value;
    return true;
}

Protocol::~Protocol()
{

}
